﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using TMDT_Nhom1A.DTO;
using System.Collections.Generic;

namespace TMDT_Nhom1A.DAO
{
    public class RegisterWebserviceDAO
    {
        private static QL_DoanhNghiepDataContext data = new QL_DoanhNghiepDataContext();
        public static bool RegisterWebservice(REGISTRY_WEBSERVICE register,int userId)
        {
            try
            {
                data.REGISTRY_WEBSERVICEs.InsertOnSubmit(register);
                data.SubmitChanges();

                return true;
            }
            catch(Exception ex)
            {
                return false;
            }
        }

        public static List<REGISTRY_WEBSERVICE> getAllRegisterWebservice()
        {
            try
            {
                var result = from res in data.REGISTRY_WEBSERVICEs
                             select res;

                return result.ToList() ;
            }
            catch (Exception ex)
            {
                return null;
            }
           
        }

        public static bool activateRegisterWebservice(int registerWebserviceID)
        {
            try
            {
                //lay ra doi tuong
                REGISTRY_WEBSERVICE registryWS = (from reg in data.REGISTRY_WEBSERVICEs
                                                  where reg.Webservice_ID == registerWebserviceID
                                                  select reg).Single();
                if (registryWS != null)
                {
                    registryWS.Activate = true;

                    //them webservice_ID vao bang user

                    data.SubmitChanges();
                    return true;
                }

                return false;

            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public static bool allowOrNotAllowUsingRegisterWebservice(int registerWebserviceID,int status)
        {
            try
            {
                //lay ra doi tuong
                REGISTRY_WEBSERVICE registryWS = (from reg in data.REGISTRY_WEBSERVICEs
                                                  where reg.Webservice_ID == registerWebserviceID
                                                  select reg).Single();
                if (registryWS != null)
                {
                    registryWS.Status = (short)status;

                    //them webservice_ID vao bang user

                    data.SubmitChanges();
                    return true;
                }

                return false;

            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
